import { DBHelper } from "../../assets/indexdb/DBHelper";

async function json (message, callback) {
  const path= message.path
  const indexedDB=message.indexedDB
  fetch(message.path).then(result => {
    if (!result.ok) {
      console.error("不能加载该路径的瓦片 : " + path)
      throw new Error(`不能加载 "${path}". Request failed with status ${result.status} : ${result.statusText}`);
  }
   return result.json();

  }).then( res => {
    if (indexedDB) {
      DBHelper.getInstance().open("3dtiles", db => {
        db.add({ "id": message.path, "value": res })
      })
    }
    callback({ data: res});
  })


}
export { json }